<?php

namespace app\data\controller\report;

use app\admin\service\WxWorkService;
use app\data\service\RecordService;
use think\admin\Controller;
use think\admin\service\AdminService;
use think\facade\Cache;

/**
 * 数据统计-总览
 * Class Observation
 * @package app\data\controller\report
 */
class Observation extends Controller
{
    /**
     * 绑定数据表
     * @var string
     */
    private $table = 'report_observation';

    /**
     * 数据统计汇总表
     * @auth true
     * @menu true
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function index()
    {
        // 设置页面标题
        $this->title = '数据统计汇总表';
        // 创建查询对象
        $query = $this->_query($this->table)->order('id desc');

        $result = $query->like('phone,username,plate_number')->equal('province#query_province,query_city#city')->dateBetween('date');

        // 数据查询分页
        if (input('output') == 'json') {
            $result = $result->page(true, false);
            $this->success('', $result);
        } else {
            $result->page();
        }
    }

    /**
     * 数据统计汇总表导出
     * @auth true
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function indexExport()
    {
        $this->index();
    }

    /**
     * 数据列表处理
     * @param array $data
     */
    protected function _page_filter(array &$data)
    {
    }

    /**
     * 表单结果处理
     * @param boolean $state
     */
    protected function _form_result(bool $state, array $data)
    {
        if ($state) {
            $this->success('保存成功！', 'javascript:history.back()');
        }
    }

    /**
     * 数据列表处理
     * @param array $data
     */
    protected function _teams_page_filter(array &$data)
    {
    }

    /**
     * 编辑
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function edit()
    {
        $this->_form($this->table, 'form');
    }

    /**
     * 表单数据处理
     * @param array $data
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    protected function _form_filter(array &$data)
    {
        $this->title = '数据统计汇总管理';
        if ($this->request->isPost()) {

        } else {

        }
    }

    /**
     * 删除
     * @throws \think\db\exception\DbException
     */
    public function remove()
    {
        $this->app->db->name($this->table)->where('id', input('id'))->delete();
        $this->success('删除成功');
    }
}